package com.titleevaluation.controller;

import com.titleevaluation.entity.Awards;
import com.titleevaluation.service.AwardsService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/applications/{applicationId}/awards")
public class AwardsController {

    private final AwardsService awardsService;

    public AwardsController(AwardsService awardsService) {
        this.awardsService = awardsService;
    }

    @PostMapping
    public ResponseEntity<Awards> createAwards(@PathVariable Long applicationId, @RequestBody Awards awards) {
        Awards createdAwards = awardsService.createAwards(applicationId, awards);
        return ResponseEntity.ok(createdAwards);
    }

    @GetMapping
    public ResponseEntity<List<Awards>> getAwardsByApplicationId(@PathVariable Long applicationId) {
        List<Awards> awards = awardsService.getAwardsByApplicationId(applicationId);
        return ResponseEntity.ok(awards);
    }

    @GetMapping("/{id}")
    public ResponseEntity<Awards> getAwardsById(@PathVariable Long id) {
        return awardsService.getAwardsById(id)
                .map(ResponseEntity::ok)
                .orElse(ResponseEntity.notFound().build());
    }

    @PutMapping("/{id}")
    public ResponseEntity<Awards> updateAwards(@PathVariable Long id, @RequestBody Awards awards) {
        Awards updatedAwards = awardsService.updateAwards(id, awards);
        return ResponseEntity.ok(updatedAwards);
    }

    @DeleteMapping("/{id}")
    public ResponseEntity<Void> deleteAwards(@PathVariable Long id) {
        awardsService.deleteAwards(id);
        return ResponseEntity.noContent().build();
    }
}

